// loading 组件


var svg = '';
svg += '<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->';
svg += '<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">';
svg += '    <defs>';
svg += '        <linearGradient x1="8.042%" y1="0%" x2="65.682%" y2="23.865%" id="a">';
svg += '            <stop stop-color="#fff" stop-opacity="0" offset="0%"/>';
svg += '            <stop stop-color="#fff" stop-opacity=".631" offset="63.146%"/>';
svg += '            <stop stop-color="#fff" offset="100%"/>';
svg += '        </linearGradient>';
svg += '    </defs>';
svg += '    <g fill="none" fill-rule="evenodd">';
svg += '        <g transform="translate(1 1)">';
svg += '            <path d="M36 18c0-9.94-8.06-18-18-18" id="Oval-2" stroke="url(#a)" stroke-width="2">';
svg += '                <animateTransform';
svg += '                    attributeName="transform"';
svg += '                    type="rotate"';
svg += '                    from="0 18 18"';
svg += '                    to="360 18 18"';
svg += '                    dur="0.9s"';
svg += '                    repeatCount="indefinite" />';
svg += '            </path>';
svg += '            <circle fill="#fff" cx="36" cy="18" r="1">';
svg += '                <animateTransform';
svg += '                    attributeName="transform"';
svg += '                    type="rotate"';
svg += '                    from="0 18 18"';
svg += '                    to="360 18 18"';
svg += '                    dur="0.9s"';
svg += '                    repeatCount="indefinite" />';
svg += '            </circle>';
svg += '        </g>';
svg += '    </g>';
svg += '</svg>';



var loadingEX = function (ele, opt) {
    this.$element = ele || $('body');
    this.defaultSetting = {
        className: '',
        loadingText: 'LOADING',
    };
    this.options = $.extend({}, this.defaultSetting, opt);
    this.stutas = false;
};
loadingEX.prototype = {
    render: function () {
        var html = '';
        html += '<div class="loadingEx ' + this.options.className + '">';
        html += '   <div class="loadingBody">';
        html += '       <div class="loadingImg"></div>';
        html += '       <div class="loadingText">' + this.options.loadingText + '</div>';
        html += '   </div>';
        html += '</div>';
        this.html = $(html);
        this.html.find('.loadingImg').append(svg);
    },
    show: function () {
        if (this.$element.find('> .loadingEx').length) {
            this.$element.find('> .loadingEx').show();
        } else {
            this.render();
            if (this.$element.selector == 'body') {
                this.html.css('position', 'fixed');
            };
            this.$element.append(this.html);
        };
    },
    hide: function () {
        this.$element.find('> .loadingEx').hide();
    },
};


export default function (ele, options) {
    return new loadingEX(ele, options);
};




// !(function ($, undefined) {
//     //定义loadingEX的方法
//     var LoadingEvent = [];
//     //在插件中使用loadingEX对象
//     $.fn.loading = function (options) {
//         console.log(this);
//         console.log(LoadingEvent);
//         var hasEvent = null;
//         for (let i = 0; i < LoadingEvent.length; i++) {
//             const element = LoadingEvent[i];
//             if (element.ele === this) {
//                 hasEvent = element.event;
//             };
//         };
//         console.log(hasEvent);
//         if (!hasEvent) {
//             var loadingItem = { ele: this, event: new loadingEX(this, options) };
//             LoadingEvent.push(loadingItem);
//             hasEvent = loadingItem.event;
//         };
//         console.log(hasEvent);
//         return hasEvent
//     };
// })(jQuery);